//
//  LKBaseNavController.swift
//  新浪微博
//
//  Created by 胡不归是大虾 on 16/9/22.
//  Copyright © 2016年 胡不归是大虾. All rights reserved.
//

import UIKit

class LKBaseNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //设置目标控制器的leftBarButtonItem
        //判断当前子控制器的数量,从而避免首页也加了左上角的按钮
        if childViewControllers.count !=  0 {
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", action: #selector(back), target: self, title: "返回")
        }
        
        //实现父类的一定要在添加按钮之前,因为实现父类方法之后就已经添加控制器了
        super.pushViewController(viewController, animated: animated)
    }
    @objc private func back ( ) {
        popViewController(animated: true)
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
